package com.mxz.common.core.web.service;

import com.mxz.common.core.web.domain.BaseEntity;
import com.mxz.common.core.web.mapper.BaseMapper;
import com.mxz.common.core.web.page.PageCommon;
import com.mxz.common.datasource.annotation.Master;
import com.mxz.common.datasource.annotation.Slave;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<M extends BaseMapper<T>,T extends BaseEntity> extends PageCommon implements BaseService<T> {

    @Autowired
    private M baseMapper;

    /**
     * 新增数据
     * @param po
     */
    @Master
    @Override
    public int insert(T po) {
        return baseMapper.insert(po);
    }

    /**
     * 通过主键删除数据
     * @param id
     */
    @Master
    @Override
    public int delete(Object id) {
        return baseMapper.delete(id);
    }

    /**
     * 通过主键数组删除数据
     * @param ids
     */
    @Master
    @Override
    public int deleteByIds(List<?> ids) {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 通过主键修改数据
     * @param po
     */
    @Master
    @Override
    public int update(T po) {
        return baseMapper.update(po);
    }

    /**
     * 通过主键查询数据
     * @param id
     */
    @Slave
    @Override
    public T getById(Object id) {
        return baseMapper.getById(id);
    }

    /**
     * 查询数据列表
     * @param po
     */
    @Slave
    @Override
    public List<T> getList(T po) {
        return baseMapper.getList(po);
    }
}
